package com.example.springboot_demo.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * <P> @Author: SongKeCheng
 * <P> Type: Class
 * <P> Description:
 * <P> Date: 2024/6/24:8:04
 */

@SuppressWarnings({"unchecked", ""})
public class GroupUtils {
    private static final Logger log = LoggerFactory.getLogger(GroupUtils.class);

    public static void main(String[] args) {
        List<Integer> group = createGroup(16);
        log.info("old group:{}",group);
        shuffleGroup(group);
        log.info("new group:{}",group);

    }

      /**
               * @param maxGroupNum 分组的最大数量
     * @return 包含1到maxGroupNum的ArrayList
     */
    public static List<Integer> createGroup(int maxGroupNum) {
        List<Integer> groupList = new ArrayList<>();
        for (int i = 1; i <= maxGroupNum; i++) {
            groupList.add(i);
        }
        return groupList;
    }

    /**
     * 随机打乱一个整数列表的顺序。
     *
     * @param groupList 要被打乱的原始整数列表
     */
    public static void shuffleGroup(List<Integer> groupList) {
        Collections.shuffle(groupList);
    }
}
